{include file="common/head"}
<head>
<title>订单评价</title>
  <style type="text/css">
    #top{background: #f60;}
    #top div{color: white;}
    .section{border:1px solid #ccc;border-radius:10px;padding: 5px 10px;background: #fff;box-shadow: 1px 1px 2px #555;}
  </style>
</head>
<body style="background: #f60;">
    <div class="container p-3 my-3 " style="max-width: 600px;"  >

    <div id="top" class="text-center row text-primary">
      <div class="col-2" >
        <span class="bi-chevron-left"></span>
      </div>
      <div class="col-8">订单评价(Comment)</div>
      <div class="col-2"></div>
    </div>
    <div style="height: 50px;"></div>

    <div class="section">
    {if $data1.id}
      <div class="text-primary">【我的评价】</div>
      <div>{$data1.create_time} <span style="color:red;font-size: 1.3rem;margin-left:10px;">{$data1.stars_name}</span></div>
      <div style="border-top:1px solid #ccc;color:#f60;">{$data1.content}</div>
    {else}
      <input type="hidden" name="order_id" id="order_id" value="{$order_id}"/>
      <div>
        <lable for="starts" class="form-label" />给对方的星级:
        <select id="stars" name="stars" class="form-control" style="font-size:1rem;color:#f60;">
            {foreach $stars as $k=>$v}
                {if $k=$data1.stars}
                    <option value="{$k}" selected >{$v}</option>
                {else}
                    <option value="{$k}" >{$v}</option>
                {/if}
            {/foreach}
        </select>
      </div>
 
      <div class="mb-3 mt-3">
        <lable for="name" class="form-label" />评价内容(Comment text):
        <textarea class="form-control" id="content" name="content" placeholder="评价内容" style="height:90px;">{$data1.content}</textarea>
      </div>

      <div style="clear: both;" class="d-grid">
        <br/>
      <button  type="button" class="btn btn-primary btn-block" onclick="doSave()">保存评价(Save)</button>
      </div>
    
  {/if}
</div>


    <div style="height: 20px;"></div>    

    <div class="section">
    {if $data2.id}
      <div class="text-primary">【来自对方的评价】</div>
      <div>{$data2.create_time} <span style="color:red;font-size: 1.3rem;margin-left:10px;">{$data2.stars_name}</span></div>
      <div style="border-top:1px solid #ccc;color:#f60;">{$data2.content}</div>
    {else}
      <div>对方尚未评价！</div>
    {/if}
    
    </div>
    <div style="height: 20px;"></div>    
    </div>

<script type="text/javascript">
    $(document).ready(function(){
      $(".bi-chevron-left").on('click',function(){
        history.back();
      })
    })


    function doSave(){

      if(!$("#content").val().trim()) {
        layer.msg("无效的评价内容!");
        return 0;
      }else{
        var content=$("#content").val().trim();
      }

      var order_id=$("#order_id").val();

      //我要推荐商品
      var chk_value =[];
      $('input[name="recom_goods_id"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
          chk_value.push($(this).val());
      });
      
      layer.confirm('是否确定保存?', {
        btn: ['Yes','No'] //按钮
      }, function(){
        
        //提交评价
        $.post('/index.php/comments/comm_edit'
          ,{
          id:$("#id").val(),
          order_id:order_id,
          content:content,
          recom_goods_id:chk_value,
          stars:$("#stars").val()
        },function(res){
          var res = JSON.parse(res);
          layer.msg(res.msg,function(){location.reload()});
        });

      }, function(){
        
        return 0;
      });
    }

</script>


</body>
</html>
